﻿using System;
using System.ComponentModel.Composition;
using Skynet.Contracts;
using Transport;
namespace Capture
{
    [ExportCaptureDevice("MME", CaptureTypes.Audio)]
    public class MmeCaptureDevice : ICaptureDevice
    {
        private MmeCapturer _capturer;

        public bool IsSupported
        {
            get { return MmeCapturer.IsSupported; }
        }

        public void Start(ITransport transport)
        {
            if (_capturer != null)
                throw new InvalidOperationException("CaptureAlreadyStarted");
            _capturer = new MmeCapturer(new RawAudioTransport(transport));
            _capturer.Initialize();
            _capturer.Start();
        }

        public void Stop()
        {
            if (_capturer == null)
                throw new InvalidOperationException("CaptureNotStarted");
            _capturer.Stop();
            _capturer.Dispose(); _capturer = null;
        }
    }
}
